# -*- encoding: utf-8 -*-
# @File    :   items.py
# @Time    :   2021/07/23 16:51:11
# @Author  :   wudongmin
# @Contact :   wudongmin@xroom.net
# @version   :  1.0

from pydantic import BaseModel
from enum import Enum
from fastapi import Query


class OrderByEnum(str, Enum):
    # 排序字段枚举
    ID = "id"
    SORT = "sort"
    WEIGHT = "weight"
    CREATED_AT = "created_at"
    UPDATED_AT = "updated_at"


class OrderMethodEnum(str, Enum):
    # 排序方式枚举
    ASC = "asc"
    DESC = "desc"


class PagniationItem(BaseModel):
    # 分页参数验证
    page: int = 1
    per_page: int = 10


class OrderItem(BaseModel):
    # 排序参数验证
    order_by: OrderByEnum = OrderByEnum.CREATED_AT.value
    order_method: OrderMethodEnum = OrderMethodEnum.DESC.value


def pagnation_common_params(page: int = Query(None, description="页数"),
                            per_page: int = Query(None, description="每页个数")):
    if page is None or per_page is None:
        return None
    return PagniationItem(page=page, per_page=per_page)


def order_common_params(order_by: str = Query(None, description="排序字段 created_at"),
                        order_method: str = Query(None, description="排序方式 asc: 正序  desc: 倒序")):
    if order_method is None or order_by is None:
        return None
    return OrderItem(order_method=order_method, order_by=order_by)
